package com.telenav.snowsweeper.controller;

import android.app.Activity;
import android.os.SystemClock;
import android.widget.Toast;

public class Notifier {
	
	private static Activity context;
	private static String info;
	private static Toast lastToast;
	private static long timeStamp;
	
	public static void init(Activity context) {
		Notifier.context = context;
	}
	
	public static void notify(final String info) {
		context.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				if (lastToast != null && info != null && !info.equals(Notifier.info))
					lastToast.cancel();
				
				if (info != null && !info.equals(Notifier.info) || SystemClock.uptimeMillis() - timeStamp > 5000) {
					Notifier.info = info;
					lastToast = Toast.makeText(context, info, Toast.LENGTH_SHORT);
					lastToast.show();
					timeStamp = SystemClock.uptimeMillis();
				}
			}
		});
	}
}
